//package org.nepu.scr.indexrate.ratecompliance.compliance;
//
//import cn.afterturn.easypoi.word.WordExportUtil;
//import cn.afterturn.easypoi.word.entity.MyXWPFDocument;
//import cn.hutool.core.bean.BeanUtil;
//import cn.hutool.core.bean.copier.CopyOptions;
//import cn.hutool.core.lang.Validator;
//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;
//import lombok.AllArgsConstructor;
//import lombok.SneakyThrows;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.poi.xwpf.usermodel.XWPFDocument;
//import org.lboot.core.domain.ResponseDTO;
//import org.lboot.core.exception.BusinessException;
//import org.lboot.jpa.utils.JpaDataUtil;
//import org.lboot.ufs.service.UfsCtl;
//import org.nepu.scr.indexrate.ratecompliance.compliance.params.ComplianceUpdateParams;
//import org.nepu.scr.indexrate.ratecompliance.complianceBuildService;
//import org.nepu.scr.indexrate.ratecompliance.compliance.params.ComplianceCreateParams;
//import org.nepu.scr.indexrate.ratecompliance.compliance.params.ComplianceData;
//import org.nepu.scr.indexrate.ratecompliance.compliance.params.ComplianceQueryParams;
//import org.nepu.scr.indexrate.ratecompliance.complianceparams.ComplianceParams;
//import org.nepu.scr.indexrate.ratecompliance.complianceparams.ComplianceParamsController;
//import org.nepu.scr.indexrate.ratecompliance.complianceparams.ComplianceParamsData;
//import org.nepu.scr.indexrate.ratecompliance.complianceparams.ComplianceParamsService;
//import org.nepu.scr.indexrate.ratecompliance.compliancescore.ComplianceScoreController;
//import org.nepu.scr.indexrate.ratecompliance.compliancescore.ComplianceScoreService;
//import org.nepu.scr.indexrate.raterisk.prerisk.params.RiskData;
//import org.nepu.scr.indexrate.raterisk.preriskparams.RiskParamsData;
//import org.nepu.scr.service.AnalyseService;
//import org.nepu.scr.indexrate.ratecompliance.ComplianceMapService;
//import org.nepu.scr.indexrate.ratecompliance.ComplianceDataService;
//import org.springframework.data.domain.Example;
//import org.springframework.data.domain.Pageable;
//import org.springframework.data.jpa.domain.Specification;
//import org.springframework.http.HttpStatus;
//import org.springframework.validation.annotation.Validated;
//import org.springframework.web.bind.annotation.*;
//
//import javax.persistence.criteria.Predicate;
//import javax.servlet.http.HttpServletResponse;
//import java.io.InputStream;
//import java.io.OutputStream;
//import java.net.URLEncoder;
//import java.nio.charset.StandardCharsets;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//import static org.nepu.scr.constant.InLevelConstant.*;
//import static org.nepu.scr.constant.SikeConstant.*;
//
//@Slf4j
//@RestController
//@RequestMapping("safe")
//@AllArgsConstructor
//@Api(tags="符合性评级结果管理")
//public class ComplianceController {
//
//    public static String TARGET;
//    ComplianceService complianceService;
//
//    ComplianceParamsService paramsService;
//
//    ComplianceParamsController paramsController;
//
//    UfsCtl ufsCtl;
//
//    AnalyseService analyseService;
//
//    ComplianceScoreService scoreService;
//
//    ComplianceScoreController scoreController;
//
//    ComplianceMapService contentMapService;
//
//    ComplianceDataService setDataService;
//
//    complianceBuildService complianceBuildService;
//
////    @PostMapping("compliances")
////    @ApiOperation(value = "新建指标评价结果管理")
//    public ResponseDTO<Object> dataCreate(@Validated @RequestBody ComplianceCreateParams params){
//
//        if(params.getComplianceId().equals("")){
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"评价任务ID不能为空");
//        }
//
//        ComplianceData data = new ComplianceData();
//        List<Compliance> dataList = complianceService.getByComplianceName(params.getComplianceId());
//
//        if (dataList.size() > 0){
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"存在指标评价任务"+params.getComplianceId());
//        }
//
//        Compliance compliance = new Compliance();
//        compliance.setComplianceName(params.getComplianceId());
//        data.setComplianceId(params.getComplianceId());
//        Compliance r = complianceService.saveOne(compliance);
//        String complianceDataId = r.getId();
//        complianceService.saveComplianceData(complianceDataId, data);
//
//        paramsController.dataCreate(params);
//        return ResponseDTO.succData(
//                r
//        );
//    }
//
//
//
////    @DeleteMapping("compliances/{id}")
////    @ApiOperation(value = "删除指标评价结果")
//    public ResponseDTO<Object> dataDelete(@PathVariable("id") String id){
//        String ri = complianceService.getOneUnwrap(id).getComplianceName();
//        complianceService.deleteComplianceData(id);
//        complianceService.deleteOne(id);
//        List<ComplianceParams> complianceParams = paramsService.getByComplianceName(ri);
//        paramsController.dataDelete(complianceParams.get(0).getId());
//        return ResponseDTO.succMsg("删除成功");
//    }
//
//
//    @PutMapping("compliances/{complianceId}/data")
//    @ApiOperation(value = "评价结果更新")
//    public ResponseDTO<Object> dataUpdate(@PathVariable("complianceId") String complianceId,@Validated @RequestBody ComplianceUpdateParams params){
//        String scoreId = params.getScoreId();
//        ComplianceData data = complianceService.readComplianceData(complianceId);
////        BeanUtil.copyProperties(params,data, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//        //更新参数
//        ComplianceParams p = new ComplianceParams();
//        p.setComplianceName(complianceService.getOneUnwrap(complianceId).getComplianceName());
//        Example<ComplianceParams> example = Example.of(p);
//        List<ComplianceParams> params1 = paramsService.getExample(example);
//        ComplianceParamsData paramsData = new ComplianceParamsData();
//        BeanUtil.copyProperties(params,paramsData, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//        paramsController.dataUpdate(params1.get(0).getId(),paramsData);
//
//        String input = null;
//        for(int i=0;i<SOURCE.length;i++){
//            if(params.getComplianceScore().containsKey(SOURCE[i])){
//                input = SOURCE[i];
//                break;
//            }
//        }
//        if(Validator.isEmpty(input)){
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"输入源错误，无法计算");
//        }
//
//        //更新结果使用算法
//        //输入源为A11x
//        String inputA11x = null;
//        for(int i=0;i<A11.length;i++){
//            if(params.getComplianceScore().containsKey(A11[i])){
//                inputA11x = A11[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA11x)){
//            TARGET = inputA11x;
//            setDataService.setData(data,judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if(Validator.isNotEmpty(data.getA111())&&
//                    Validator.isNotEmpty(data.getA112())&&
//                    Validator.isNotEmpty(data.getA113())&&
//                    Validator.isNotEmpty(data.getA114())&&
//                    Validator.isNotEmpty(data.getA115())&&
//                    Validator.isNotEmpty(data.getA116())){
//                printMatrix(buildMatrix("A11",data));
//                String resultA11 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA11(), buildMatrix("A11",data));
//                setDataService.setData(data,resultA11,TARGET);
//                if(Validator.isNotEmpty(data.getA11())&&
//                        Validator.isNotEmpty(data.getA12())){
//                    String resultA1 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA1(), buildMatrix("A1",data));
//                    setDataService.setData(data,resultA1,TARGET);
//                    if(Validator.isNotEmpty(data.getA1())&&
//                            Validator.isNotEmpty(data.getA2())&&
//                            Validator.isNotEmpty(data.getA3())&&
//                            Validator.isNotEmpty(data.getA4())&&
//                            Validator.isNotEmpty(data.getA5())){
//                        String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                        setDataService.setData(data,resultA,TARGET);
//                    }
//                }
//            }
//        }
//
//        //输入源为A12
//        if(params.getComplianceScore().containsKey("A12")) {
//            TARGET = "A12";
//            setDataService.setData(data, judgeGrade(params.getComplianceScore().get("A12")),TARGET);
//            if (Validator.isNotEmpty(data.getA11()) &&
//                    Validator.isNotEmpty(data.getA12())) {
//                String resultA1 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA1(), buildMatrix("A1", data));
//                setDataService.setData(data, resultA1,TARGET);
//                if(Validator.isNotEmpty(data.getA1())&&
//                        Validator.isNotEmpty(data.getA2())&&
//                        Validator.isNotEmpty(data.getA3())&&
//                        Validator.isNotEmpty(data.getA4())&&
//                        Validator.isNotEmpty(data.getA5())){
//                    String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                    setDataService.setData(data,resultA,TARGET);
//                }
//            }
//        }
//
//        //输入源为A2x
//        String inputA2x = null;
//        for(int i=0;i<A2.length;i++){
//            if(params.getComplianceScore().containsKey(A2[i])){
//                inputA2x = A2[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA2x)) {
//            TARGET = inputA2x;
//            setDataService.setData(data, judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if (Validator.isNotEmpty(data.getA21()) &&
//                    Validator.isNotEmpty(data.getA22())&&
//                    Validator.isNotEmpty(data.getA23())) {
//                String resultA2 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA2(), buildMatrix("A2", data));
//                setDataService.setData(data, resultA2,TARGET);
//                if(Validator.isNotEmpty(data.getA1())&&
//                        Validator.isNotEmpty(data.getA2())&&
//                        Validator.isNotEmpty(data.getA3())&&
//                        Validator.isNotEmpty(data.getA4())&&
//                        Validator.isNotEmpty(data.getA5())){
//                    String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                    setDataService.setData(data,resultA,TARGET);
//                }
//            }
//        }
//
//        //输入源为A3x
//        String inputA3x = null;
//        for(int i=0;i<A3.length;i++){
//            if(params.getComplianceScore().containsKey(A3[i])){
//                inputA3x = A3[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA3x)) {
//            TARGET = inputA3x;
//            setDataService.setData(data, judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if (Validator.isNotEmpty(data.getA31()) &&
//                    Validator.isNotEmpty(data.getA32())) {
//                String resultA3 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA3(), buildMatrix("A3", data));
//                setDataService.setData(data, resultA3,TARGET);
//                if(Validator.isNotEmpty(data.getA1())&&
//                        Validator.isNotEmpty(data.getA2())&&
//                        Validator.isNotEmpty(data.getA3())&&
//                        Validator.isNotEmpty(data.getA4())&&
//                        Validator.isNotEmpty(data.getA5())){
//                    String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                    setDataService.setData(data,resultA,TARGET);
//                }
//            }
//        }
//
//        //输入源为A41x
//        String inputA41x = null;
//        for(int i=0;i<A41.length;i++){
//            if(params.getComplianceScore().containsKey(A41[i])){
//                inputA41x = A41[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA41x)){
//            TARGET = inputA41x;
//            setDataService.setData(data,judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if(Validator.isNotEmpty(data.getA411())&&
//                    Validator.isNotEmpty(data.getA412())&&
//                    Validator.isNotEmpty(data.getA413())){
//                String resultA41 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA41(), buildMatrix("A41",data));
//                setDataService.setData(data,resultA41,TARGET);
//                if(Validator.isNotEmpty(data.getA41())&&
//                        Validator.isNotEmpty(data.getA42())&&
//                        Validator.isNotEmpty(data.getA43())&&
//                        Validator.isNotEmpty(data.getA44())&&
//                        Validator.isNotEmpty(data.getA45())){
//                    String resultA4 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA4(), buildMatrix("A4",data));
//                    setDataService.setData(data,resultA4,TARGET);
//                    if(Validator.isNotEmpty(data.getA1())&&
//                            Validator.isNotEmpty(data.getA2())&&
//                            Validator.isNotEmpty(data.getA3())&&
//                            Validator.isNotEmpty(data.getA4())&&
//                            Validator.isNotEmpty(data.getA5())){
//                        String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                        setDataService.setData(data,resultA,TARGET);
//                    }
//                }
//            }
//        }
//
//        //输入源为A42x
//        String inputA42x = null;
//        for(int i=0;i<A42.length;i++){
//            if(params.getComplianceScore().containsKey(A42[i])){
//                inputA42x = A42[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA42x)){
//            TARGET = inputA42x;
//            setDataService.setData(data,judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if(Validator.isNotEmpty(data.getA421())&&
//                    Validator.isNotEmpty(data.getA422())){
//                String resultA42 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA42(), buildMatrix("A42",data));
//                setDataService.setData(data,resultA42,TARGET);
//                if(Validator.isNotEmpty(data.getA41())&&
//                        Validator.isNotEmpty(data.getA42())&&
//                        Validator.isNotEmpty(data.getA43())&&
//                        Validator.isNotEmpty(data.getA44())&&
//                        Validator.isNotEmpty(data.getA45())){
//                    String resultA4 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA4(), buildMatrix("A4",data));
//                    setDataService.setData(data,resultA4,TARGET);
//                    if(Validator.isNotEmpty(data.getA1())&&
//                            Validator.isNotEmpty(data.getA2())&&
//                            Validator.isNotEmpty(data.getA3())&&
//                            Validator.isNotEmpty(data.getA4())&&
//                            Validator.isNotEmpty(data.getA5())){
//                        String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                        setDataService.setData(data,resultA,TARGET);
//                    }
//                }
//            }
//        }
//
//        //输入源为A43
//        if(params.getComplianceScore().containsKey("A43")) {
//            TARGET = "A43";
//            setDataService.setData(data, judgeGrade(params.getComplianceScore().get("A43")),TARGET);
//            if (Validator.isNotEmpty(data.getA41()) &&
//                    Validator.isNotEmpty(data.getA42())&&
//                    Validator.isNotEmpty(data.getA43())&&
//                    Validator.isNotEmpty(data.getA44())&&
//                    Validator.isNotEmpty(data.getA45())) {
//                String resultA4 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA4(), buildMatrix("A4", data));
//                setDataService.setData(data, resultA4,TARGET);
//                if(Validator.isNotEmpty(data.getA1())&&
//                        Validator.isNotEmpty(data.getA2())&&
//                        Validator.isNotEmpty(data.getA3())&&
//                        Validator.isNotEmpty(data.getA4())&&
//                        Validator.isNotEmpty(data.getA5())){
//                    String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                    setDataService.setData(data,resultA,TARGET);
//                }
//            }
//        }
//
//        //输入源为A44x
//        String inputA44x = null;
//        for(int i=0;i<A44.length;i++){
//            if(params.getComplianceScore().containsKey(A44[i])){
//                inputA44x = A44[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA44x)){
//            TARGET = inputA44x;
//            setDataService.setData(data,judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if(Validator.isNotEmpty(data.getA441())&&
//                    Validator.isNotEmpty(data.getA442())&&
//                    Validator.isNotEmpty(data.getA443())){
//                String resultA44 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA44(), buildMatrix("A44",data));
//                setDataService.setData(data,resultA44,TARGET);
//                if(Validator.isNotEmpty(data.getA41())&&
//                        Validator.isNotEmpty(data.getA42())&&
//                        Validator.isNotEmpty(data.getA43())&&
//                        Validator.isNotEmpty(data.getA44())&&
//                        Validator.isNotEmpty(data.getA45())){
//                    String resultA4 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA4(), buildMatrix("A4",data));
//                    setDataService.setData(data,resultA4,TARGET);
//                    if(Validator.isNotEmpty(data.getA1())&&
//                            Validator.isNotEmpty(data.getA2())&&
//                            Validator.isNotEmpty(data.getA3())&&
//                            Validator.isNotEmpty(data.getA4())&&
//                            Validator.isNotEmpty(data.getA5())){
//                        String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                        setDataService.setData(data,resultA,TARGET);
//                    }
//                }
//            }
//        }
//
//        //输入源为A45x
//        String inputA45x = null;
//        for(int i=0;i<A45.length;i++){
//            if(params.getComplianceScore().containsKey(A45[i])){
//                inputA45x = A45[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA45x)){
//            TARGET = inputA45x;
//            setDataService.setData(data,judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if(Validator.isNotEmpty(data.getA451())&&
//                    Validator.isNotEmpty(data.getA452())){
//                String resultA45 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA45(), buildMatrix("A45",data));
//                setDataService.setData(data,resultA45,TARGET);
//                if(Validator.isNotEmpty(data.getA41())&&
//                        Validator.isNotEmpty(data.getA42())&&
//                        Validator.isNotEmpty(data.getA43())&&
//                        Validator.isNotEmpty(data.getA44())&&
//                        Validator.isNotEmpty(data.getA45())){
//                    String resultA4 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA4(), buildMatrix("A4",data));
//                    setDataService.setData(data,resultA4,TARGET);
//                    if(Validator.isNotEmpty(data.getA1())&&
//                            Validator.isNotEmpty(data.getA2())&&
//                            Validator.isNotEmpty(data.getA3())&&
//                            Validator.isNotEmpty(data.getA4())&&
//                            Validator.isNotEmpty(data.getA5())){
//                        String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                        setDataService.setData(data,resultA,TARGET);
//                    }
//                }
//            }
//        }
//
//        //输入源为A5x
//        String inputA5x = null;
//        for(int i=0;i<A5.length;i++){
//            if(params.getComplianceScore().containsKey(A5[i])){
//                inputA5x = A5[i];
//                break;
//            }
//        }
//        if(Validator.isNotEmpty(inputA5x)) {
//            TARGET = inputA5x;
//            setDataService.setData(data, judgeGrade(params.getComplianceScore().get(TARGET)),TARGET);
//            if (Validator.isNotEmpty(data.getA51()) &&
//                    Validator.isNotEmpty(data.getA52())&&
//                    Validator.isNotEmpty(data.getA53())&&
//                    Validator.isNotEmpty(data.getA54())&&
//                    Validator.isNotEmpty(data.getA55())&&
//                    Validator.isNotEmpty(data.getA56())) {
//                String resultA5 = analyseService.analyse(scoreService.readComplianceData(scoreId).getA5(), buildMatrix("A5", data));
//                setDataService.setData(data, resultA5,TARGET);
//                if(Validator.isNotEmpty(data.getA1())&&
//                        Validator.isNotEmpty(data.getA2())&&
//                        Validator.isNotEmpty(data.getA3())&&
//                        Validator.isNotEmpty(data.getA4())&&
//                        Validator.isNotEmpty(data.getA5())){
//                    String resultA = analyseService.analyse(scoreService.readComplianceData(scoreId).getA(), buildMatrix("A",data));
//                    setDataService.setData(data,resultA,TARGET);
//                }
//            }
//        }
//
//        ComplianceData returnData = complianceService.saveComplianceData(complianceId, data);
//
//        return ResponseDTO.succData(
//                complianceBuildService.buildData(returnData)
//        );
//    }
//
//    @GetMapping("compliances")
//    @ApiOperation(value = "指标评价结果列表")
//    public ResponseDTO<Object> dataList(ComplianceQueryParams params){
//        Pageable pageable = JpaDataUtil.buildPageable(params);
//        if (Validator.isEmpty(params.getSearchKey())){
//            Compliance data = new Compliance();
//            BeanUtil.copyProperties(params,data, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
//            Example<Compliance> example = Example.of(data);
//            return ResponseDTO.succData(
//                    complianceService.getAll(pageable,example)
//            );
//        }else {
//            Specification<Compliance> spec = (root, query, cb) -> {
//                List<Predicate> list = new ArrayList<>();
//                Predicate p1 = cb.like(root.get("complianceId").as(String.class),"%"+params.getSearchKey()+"%");
//                list.add(p1);
//                Predicate[] predicates = new Predicate[list.size()];
//                return cb.or(list.toArray(predicates));
//            };
//            return ResponseDTO.succData(
//                    complianceService.getAll(pageable, spec)
//            );
//        }
//    }
//
//    @GetMapping("compliances/{id}")
//    @ApiOperation(value = "指标评价结果查询")
//    public ResponseDTO<Object> dataQuery(@PathVariable("id") String id){
//        ComplianceData complianceData = complianceService.readComplianceData(id);
//        return ResponseDTO.succData(
//                complianceBuildService.buildData(complianceData)
//        );
//    }
//
//    @GetMapping("compliances/schemes/export")
//    @ApiOperation(value = "指标评价结果导出")
//    @SneakyThrows
//    public void wordExport(@RequestParam("complianceDataId") String complianceDataId,@RequestParam("complianceParamsId") String complianceParamsId, @RequestParam(value = "templateFileId",required = false) String templateFileId
//            , HttpServletResponse response){
//        InputStream stream = ufsCtl.getFileStream(templateFileId);
//        ComplianceParamsData exportParamsData = paramsService.readComplianceData(complianceParamsId);
//        ComplianceData exportData = complianceService.readComplianceData(complianceDataId);
//        XWPFDocument document = new MyXWPFDocument(stream);
//        //生成文本内容Map
//        Map<String, Object> contentMap = contentMapService.buildContentMap(complianceDataId,complianceParamsId,exportData,exportParamsData);
//
//        //替换文本内容
//        WordExportUtil.exportWord07(document, contentMap);
//
//        //返回流
//        response.setHeader("content-type", "application/octet-stream");
//        response.setContentType("application/octet-stream;charset=UTF-8");
//        /**
//         * 修改导出文件名称
//         */
//        String encodedFileName = URLEncoder.encode(exportData.getComplianceId() + "安全评价报告.docx", StandardCharsets.UTF_8.toString());
//        response.setHeader("Content-Disposition", "attachment; filename=\"" + encodedFileName + "\"; filename*=utf-8''" + encodedFileName);
////        response.setHeader("Content-Disposition", "attachment; filename=" + encodedFileName+".docx");
//        OutputStream outputStream = response.getOutputStream();
//        document.write(outputStream);
//        outputStream.flush();
//
//        outputStream.close();
//    }
//
//
//    //构建隶属度矩阵
//    // A   优秀 良好 一般 较差 极差
//    // A1  1    0   0   0   0
//    // A2  1    0   0   0   0
//    // A3  0    0   0   0   1
//    // A4  0    1   0   0   0
//    @SneakyThrows
//    public Double[][] buildMatrix(String input, ComplianceData data){
//
//        Double[][] matrix = null;
//
//        if(input.equals("A")) {
//            //构建A隶属度矩阵
//            Double[][] m = new Double[A.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA1()));
//            m[1] = buildMatrix(judgeNumber(data.getA2()));
//            m[2] = buildMatrix(judgeNumber(data.getA3()));
//            m[3] = buildMatrix(judgeNumber(data.getA4()));
//            m[4] = buildMatrix(judgeNumber(data.getA5()));
//            TARGET = "A";
//            matrix=m;
//        }else if(input.equals("A1")){
//            //构建A1隶属度矩阵
//            Double[][] m = new Double[A1.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA11()));
//            m[1] = buildMatrix(judgeNumber(data.getA12()));
//            TARGET = "A1";
//            matrix=m;
//        }else if(input.equals("A2")){
//            //构建A2隶属度矩阵
//            Double[][] m = new Double[A2.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA21()));
//            m[1] = buildMatrix(judgeNumber(data.getA22()));
//            m[2] = buildMatrix(judgeNumber(data.getA23()));
//            TARGET = "A2";
//            matrix=m;
//        }else if(input.equals("A3")){
//            //构建A3隶属度矩阵
//            Double[][] m = new Double[A3.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA31()));
//            m[1] = buildMatrix(judgeNumber(data.getA32()));
//            TARGET = "A3";
//            matrix=m;
//        }else if(input.equals("A4")){
//            //构建A4隶属度矩阵
//            Double[][] m = new Double[A4.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA41()));
//            m[1] = buildMatrix(judgeNumber(data.getA42()));
//            m[2] = buildMatrix(judgeNumber(data.getA43()));
//            m[3] = buildMatrix(judgeNumber(data.getA44()));
//            m[4] = buildMatrix(judgeNumber(data.getA45()));
//            TARGET = "A4";
//            matrix=m;
//        }else if(input.equals("A5")){
//            //构建A5隶属度矩阵
//            Double[][] m = new Double[A5.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA51()));
//            m[1] = buildMatrix(judgeNumber(data.getA52()));
//            m[2] = buildMatrix(judgeNumber(data.getA53()));
//            m[3] = buildMatrix(judgeNumber(data.getA54()));
//            m[4] = buildMatrix(judgeNumber(data.getA55()));
//            m[5] = buildMatrix(judgeNumber(data.getA56()));
//            TARGET = "A5";
//            matrix=m;
//        }else if(input.equals("A11")){
//            //构建A11隶属度矩阵
//            Double[][] m = new Double[A11.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA111()));
//            m[1] = buildMatrix(judgeNumber(data.getA112()));
//            m[2] = buildMatrix(judgeNumber(data.getA113()));
//            m[3] = buildMatrix(judgeNumber(data.getA114()));
//            m[4] = buildMatrix(judgeNumber(data.getA115()));
//            m[5] = buildMatrix(judgeNumber(data.getA116()));
//            TARGET = "A11";
//            matrix=m;
//        }else if(input.equals("A41")){
//            //构建A41隶属度矩阵
//            Double[][] m = new Double[A41.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA411()));
//            m[1] = buildMatrix(judgeNumber(data.getA412()));
//            m[2] = buildMatrix(judgeNumber(data.getA413()));
//            TARGET = "A41";
//            matrix=m;
//        }else if(input.equals("A42")){
//            //构建A42隶属度矩阵
//            Double[][] m = new Double[A42.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA421()));
//            m[1] = buildMatrix(judgeNumber(data.getA422()));
//            TARGET = "A42";
//            matrix=m;
//        }else if(input.equals("A44")){
//            //构建A44隶属度矩阵
//            Double[][] m = new Double[A44.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA441()));
//            m[1] = buildMatrix(judgeNumber(data.getA442()));
//            m[2] = buildMatrix(judgeNumber(data.getA443()));
//            TARGET = "A44";
//            matrix=m;
//        }else if(input.equals("A45")){
//            //构建A45隶属度矩阵
//            Double[][] m = new Double[A45.length][GRADE];
//            m[0] = buildMatrix(judgeNumber(data.getA451()));
//            m[1] = buildMatrix(judgeNumber(data.getA452()));
//            TARGET = "A45";
//            matrix=m;
//        }else{
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"构建隶属度矩阵失败");
//        }
//        return  matrix;
//    }
//
//    //构建隶属度数组
//    public static Double[] buildMatrix(Double d){
//        Double[] result = {0.0,0.0,0.0,0.0,0.0};
//
//        if(d>1.0){
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"输入指标比错误应大于等于0.0小于1.0");
//        } else if (d >= ONE) {
//            result[0] = 1.0;
//        } else if (d >= TWO) {
//            result[1] = 1.0;
//        } else if (d >= THREE) {
//            result[2] = 1.0;
//        } else if (d >= FORE) {
//            result[3] = 1.0;
//        } else if (d >= FIVE) {
//            result[4] = 1.0;
//        }else {
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"输入指标比错误应大于等于0.0小于1.0");
//        }
//        return result;
//    }
//
//    @SneakyThrows
//    public static Double judgeNumber (String grade){
//        if(grade.equals(ONEG)){
//            return ONE;
//        }else if (grade.equals(TWOG)){
//            return TWO;
//        }else if (grade.equals(THREEG)){
//            return THREE;
//        }else if (grade.equals(FOREG)){
//            return FORE;
//        }else{
//            return FIVE;
//        }
//    }
//
//
//    //矩阵输出
//    @SneakyThrows
//    public static void printMatrix(Double[][] matrix){
//        System.out.println("矩阵输出：");
//        for (int i = 0; i < matrix.length; i++) {
//            System.out.print("[");
//            for (int j = 0; j < matrix[i].length; j++) {
//                System.out.print(matrix[i][j]+" ");
//            }
//            System.out.println("]");
//        }
//    }
//
//    //判断子指标是否完整
//    @SneakyThrows
//    public static Boolean keysToCheck (Map<String,Double> scoreMap,String[] keys){
//        Boolean exist = true;
//        for (String key : keys) {
//            if (!scoreMap.containsKey(key)) {
//                exist = false;
//                break;
//            }
//        }
//        return exist;
//    }
//
//
//    @SneakyThrows
//    public static String judgeGrade (Double maxIndex){
//        if(maxIndex>1.0){
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"输入指标比错误应大于等于0.0小于1.0");
//        }
//        if(maxIndex<0.0){
//            throw new BusinessException(HttpStatus.BAD_REQUEST,"输入指标比错误应大于等于0.0小于1.0");
//        }
//        if(maxIndex>=ONE){
//            return ONEG;
//        }else if (maxIndex>=TWO){
//            return TWOG;
//        }else if (maxIndex>=THREE){
//            return THREEG;
//        }else if (maxIndex>=FORE){
//            return FOREG;
//        }else{
//            return FIVEG;
//        }
//    }
//}
